﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp4
{
    /// <summary>
    /// MyStatusBar.xaml 的交互逻辑
    /// </summary>
    public partial class MyStatusBar : Window
    {
        public MyStatusBar()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 加载当前项目下的文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExec_Click(object sender, RoutedEventArgs e)
        {
            var dir = new DirectoryInfo(Environment.CurrentDirectory);
            var files = dir.GetFiles();
            processBar.Maximum = files.Length;
            var rand = new Random();

            Task.Run(async ()=>
            {
                this.Dispatcher.Invoke(async () =>
                {
                    txtFile.Text = "正在加载";
                    foreach (var file in files)
                    {
                        txtFile.Text = file.Name;
                        processBar.Value++;
                        await Task.Delay(rand.Next(100, 800));
                    }
                    processBar.Visibility= Visibility.Collapsed;
                });
                
            });
        }
    }
}
